package com.carrental.api.ums.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.carrental.api.common.query.CommonQueryParam;
import com.carrental.api.ums.domain.bo.UmsFeedbackBo;
import com.carrental.api.ums.domain.vo.UmsFeedbackVo;
import com.carrental.common.response.CommonPage;
import com.carrental.common.response.CommonResult;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.carrental.common.annotation.RepeatSubmit;
import com.carrental.common.annotation.Log;
import com.carrental.common.core.controller.BaseController;
import com.carrental.common.core.domain.PageQuery;
import com.carrental.common.core.domain.R;
import com.carrental.common.core.validate.AddGroup;
import com.carrental.common.core.validate.EditGroup;
import com.carrental.common.core.validate.QueryGroup;
import com.carrental.common.enums.BusinessType;
import com.carrental.common.utils.poi.ExcelUtil;
import com.carrental.api.ums.domain.vo.UmsFeedbackVo;
import com.carrental.api.ums.domain.bo.UmsFeedbackBo;
import com.carrental.api.ums.service.IUmsFeedbackService;
import com.carrental.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 用户反馈信息Controller
 *
 * @author liangyi
 * @date 2022-03-27
 */
@Validated
@Api(value = "用户反馈信息控制器", tags = {"用户反馈信息管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/ums/feedback")
public class UmsFeedbackController{

    private final IUmsFeedbackService feedbackService;
    /**
     * 导出用户反馈信息列表
     */
    @ApiOperation("导出用户反馈信息列表")
    @SaCheckPermission("ums:feedback:export")
    @Log(title = "用户反馈信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated UmsFeedbackBo bo, HttpServletResponse response) {
        List<UmsFeedbackVo> list = feedbackService.feedbackList(new CommonQueryParam());
        ExcelUtil.exportExcel(list, "用户反馈信息", UmsFeedbackVo.class, response);
    }
    @PostMapping()
    @ApiOperation("添加用户")
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Boolean> feedbackCreate(@RequestBody UmsFeedbackBo feedback) {
        return CommonResult.success(feedbackService.create(feedback));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除用户信息")
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Boolean> feedbackRemove(@ApiParam(name = "id", value = "用户标识", required = true)
                                            @PathVariable Long id) {
        return CommonResult.success(feedbackService.delete(id));
    }

    @PutMapping("/{id}")
    @ApiOperation("修改用户信息")
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Boolean> feedbackUpdate(
        @ApiParam(name = "id", value = "用户标识", required = true)
        @PathVariable Long id, @RequestBody UmsFeedbackBo feedback) {
        return CommonResult.success(feedbackService.update(id, feedback));
    }

    @GetMapping()
    @ApiOperation("获取用户列表")
    public CommonResult<List<UmsFeedbackVo>> feedbackList(CommonQueryParam commonQueryParam) {
        return CommonResult.success(feedbackService.feedbackList(commonQueryParam));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取用户详情")
    public CommonResult<UmsFeedbackVo> feedbackObj(@PathVariable Long id) {
        return CommonResult.success(feedbackService.detail(id));
    }

    @GetMapping("/page")
    @ApiOperation("获取用户分页")
    public CommonResult<CommonPage<UmsFeedbackVo>> feedbackPage(CommonQueryParam commonQueryParam) {
        return CommonResult.success(CommonPage.restPage(feedbackService.feedbackPage(commonQueryParam)));
    }
}
